import 'package:demo/resources.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';

class SystemUiStyle {
  static Future<void> uiMode(SystemUiMode mode, {List<SystemUiOverlay>? overlays}) async {
    SystemChrome.setEnabledSystemUIMode(mode, overlays: overlays);
  }

  static SystemUiOverlayStyle uiOverlay(Brightness brightness,
      {Color statusBarColor = Resources.transparent, Color systemNavigationBarColor = Resources.transparent}) {
    return SystemUiOverlayStyle(
        statusBarColor: statusBarColor,
        statusBarIconBrightness: brightness,
        statusBarBrightness: brightness,
        systemStatusBarContrastEnforced: false,
        systemNavigationBarColor: systemNavigationBarColor,
        systemNavigationBarIconBrightness: brightness,
        systemNavigationBarDividerColor: systemNavigationBarColor,
        systemNavigationBarContrastEnforced: false);
  }

  static Future<void> setOrientation([Orientation? orientation]) async {
    debugPrint("setOrientation:${orientation?.name}");
    if (orientation == null) {
      await SystemChrome.setPreferredOrientations(
          [ DeviceOrientation.portraitUp, DeviceOrientation.portraitDown,DeviceOrientation.landscapeRight, DeviceOrientation.landscapeLeft]);
      return;
    }
    switch (orientation) {
      case Orientation.portrait:
        await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
        break;
      case Orientation.landscape:
        await SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
        break;
    }
  }
}
